<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      function makeMatrixArray(len) {
        let array = [];
        for (let i = 0; i < len; i++) {
          array[i] = [];
          for (let j = 0; j < len; j++) {
            array[i][j] = Math.round(Math.random());
          }
        }
        return array;
      }

      //   行数组，列数组
      {
        let arr = makeMatrixArray(4);
        console.log(arr);
        console.log(getRow(arr, 1));
        console.log(getColumn(arr, 2));
        function getRow(arr, rowIndex) {
          const row = [];
          for (let index = 0; index < arr.length; index++) {
            row.push(arr[rowIndex][index]);
          }
          return row;
        }
        function getColumn(arr, columnIndex) {
          const column = [];
          for (let index = 0; index < arr.length; index++) {
            column.push(arr[index][columnIndex]);
          }
          return column;
        }
      }
    </script>
  </body>
</html>
